home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Games / GNU Chess 3.0.3 / src / update.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-26  |  8.7 KB  |  360 lines  |  [TEXT/CWIE]

  1. /*
  2.   Mac interface for GNU Chess
  3.  
  4.   Revision: 10 Feb 1991
  5.  
  6.   Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.
  7.   Copyright (c) 1991  Airy ANDRE
  8.  
  9.     expanded game save, list, and restore features
  10.     optional auto-updating of positional information
  11.  
  12.   This file is part of CHESS.
  13.  
  14.   CHESS is distributed in the hope that it will be useful,
  15.   but WITHOUT ANY WARRANTY.  No author or distributor
  16.   accepts responsibility to anyone for the consequences of using it
  17.   or for whether it serves any particular purpose or works at all,
  18.   unless he says so in writing.  Refer to the CHESS General Public
  19.   License for full details.
  20.  
  21.   Everyone is granted permission to copy, modify and redistribute
  22.   CHESS, but only under the conditions described in the
  23.   CHESS General Public License.   A copy of this license is
  24.   supposed to have been given to you along with CHESS so you
  25.   can know your rights and responsibilities.  It should be in a
  26.   file named COPYING.  Among other things, the copyright notice
  27.   and this notice must be preserved on all copies.
  28.   */
  29.  
  30. #include <stdio.h>
  31. #include "math.h"
  32.  
  33. #include "DragMgr.h"
  34. #include "gnuchess.h"
  35. #include "macintf.h"
  36.  
  37.  
  38. UserItemUPP    UpdateGraphicUPP;
  39. UserItemUPP    UpdateCaseUPP;
  40. UserItemUPP    UpdateChronosUPP;
  41. UserItemUPP    UpdateValueUPP;
  42. UserItemUPP    UpdateMsgUPP;
  43. UserItemUPP    UpdateThinkUPP;
  44. UserItemUPP    UpdateListeUPP;
  45.  
  46.  
  47. void InitUPPs(void) 
  48. {
  49.     UpdateGraphicUPP = NewUserItemProc(UpdateGraphic);
  50.     UpdateCaseUPP = NewUserItemProc(UpdateCase);
  51.     UpdateChronosUPP = NewUserItemProc(UpdateChronos);
  52.     UpdateValueUPP = NewUserItemProc(UpdateValue);
  53.     UpdateMsgUPP = NewUserItemProc(UpdateMsg);
  54.     UpdateThinkUPP = NewUserItemProc(UpdateThink);
  55.     UpdateListeUPP = NewUserItemProc(UpdateListe);
  56. }
  57.  
  58.  
  59. /* Redraw the Window */
  60. pascal void UpdateGraphic(WindowPtr theWindow, int ItemNo)
  61. {
  62.      GrafPtr SavePort;
  63.  
  64.     if (ItemNo==1) {
  65.         GetPort(&SavePort);
  66.         SetPort(WindBoard);
  67.         CopyBits(&OffScreenBits,&WindBoard->portBits,&chessRectOff,&chessRectOff,
  68.                         srcCopy,0L);
  69.         SetPort(SavePort);
  70.     }
  71. }
  72.  
  73.  
  74. /* Redraw the clocks */
  75. pascal void UpdateChronos(WindowPtr theWindow, int ItemNo)
  76. {
  77.  
  78.     GrafPtr SavePort;
  79.     int i,j;
  80.      Rect r;
  81.     char time[9];
  82.  
  83.       short h, m, s;
  84.   
  85.   
  86.     GetPort(&SavePort);
  87.     SetPort(WindThink);
  88.  
  89.     i = (nameRec.right-nameRec.left)/2;
  90.  
  91.     if (ItemNo) {
  92.         SetRect(&r,nameRec.left,nameRec.top,nameRec.left+i,nameRec.bottom);
  93.         FillRect(&nameRec,(ConstPatternParam)&whitePat);
  94.         SetRect(&r,nameRec.left+i,nameRec.top,nameRec.right,nameRec.bottom);
  95.         FillRect(&r,(ConstPatternParam)&blackPat);
  96.     }
  97.     
  98.     if (TCflag[white])
  99.     {
  100.       if (towho == white) {
  101.               h = (TimeControl.clock[white] - et) / 3600;
  102.               m = ((TimeControl.clock[white] - et) / 60) % 60;
  103.               s = (TimeControl.clock[white] - et) % 60;
  104.       } else {
  105.               h = TimeControl.clock[white] / 3600;
  106.               m = (TimeControl.clock[white] / 60) % 60;
  107.               s = TimeControl.clock[white] % 60;
  108.       }
  109.     } else
  110.   if (towho == white) {
  111.               h = et / 3600;
  112.               m = (et / 60) % 60;
  113.               s = et % 60;
  114.   } else {
  115.               h = TimeControl.clock[white] / 3600;
  116.               m = (TimeControl.clock[white] / 60) % 60;
  117.               s = TimeControl.clock[white] % 60;
  118.   }
  119.  
  120.   if (h < 0)
  121.     h = 0;
  122.   if (m < 0)
  123.     m = 0;
  124.   if (s < 0)
  125.     s = 0;
  126.  
  127.     time[0] = 8;
  128.     time[1] = '0'+h/10;
  129.     time[2] = '0'+h%10;
  130.     time[3] = ':';
  131.     time[4] = '0'+m/10;
  132.     time[5] = '0'+m%10;
  133.     time[6] = ':';
  134.     time[7] = '0'+s/10;
  135.     time[8] = '0'+s%10;
  136.     TextMode(srcCopy);
  137.     MoveTo((short)(nameRec.left+i-5-StringWidth((ConstStr255Param)time)),(short)(nameRec.top+15));
  138.     DrawString((ConstStr255Param)time);
  139.     
  140.   if (TCflag[black])
  141.     {
  142.       if (towho == black) {
  143.               h = (TimeControl.clock[black] - et) / 3600;
  144.               m = ((TimeControl.clock[black] - et) / 60) % 60;
  145.               s = (TimeControl.clock[black] - et) % 60;
  146.       } else {
  147.               h = TimeControl.clock[black] / 3600;
  148.               m = (TimeControl.clock[black] / 60) % 60;
  149.               s = TimeControl.clock[black] % 60;
  150.       }
  151.     } else
  152.   if (towho == black) {
  153.            h = et / 3600;
  154.           m = (et / 60) % 60;
  155.           s = et % 60;
  156.   } else {
  157.               h = TimeControl.clock[black] / 3600;
  158.               m = (TimeControl.clock[black] / 60) % 60;
  159.               s = TimeControl.clock[black] % 60;
  160.   }
  161.   
  162.   if (h < 0)
  163.     h = 0;
  164.   if (m < 0)
  165.     m = 0;
  166.   if (s < 0)
  167.     s = 0;
  168.  
  169.     time[0] = 8;
  170.     time[1] = '0'+h/10;
  171.     time[2] = '0'+h%10;
  172.     time[3] = ':';
  173.     time[4] = '0'+m/10;
  174.     time[5] = '0'+m%10;
  175.     time[6] = ':';
  176.     time[7] = '0'+s/10;
  177.     time[8] = '0'+s%10;
  178.     TextMode(notSrcCopy);
  179.     MoveTo((short)(nameRec.right-5-StringWidth((ConstStr255Param)time)),(short)(nameRec.top+15));
  180.     DrawString((ConstStr255Param)time);
  181.  
  182.      SetPort(SavePort);         
  183. }
  184.  
  185. pascal void UpdateMsg(WindowPtr theWindow, int ItemNo)
  186. {
  187.      GrafPtr SavePort;
  188.      int val;
  189.      int sq;
  190.      Str255 str;
  191.      
  192.      GetPort(&SavePort);
  193.     SetPort(WindThink);
  194.     FrameRect(&MsgFRec);
  195.     
  196.     MoveTo(MsgRec.left+1,MsgRec.top+16);
  197.     TextMode(srcCopy);
  198.     MoveTo(MsgRec.right-5-StringWidth(Msg),MsgRec.top+15);
  199.     FillRect(&MsgRec,(ConstPatternParam)&whitePat);
  200.     DrawString(Msg);
  201.  
  202.     SetPort(SavePort);
  203. }
  204.  
  205. pascal void UpdateThink(WindowPtr theWindow, int ItemNo)
  206. {
  207.      GrafPtr SavePort;
  208.      int num = ItemNo - 2;
  209.      int i,h,v;
  210.      Str255 *tm = ThinkMove[num];
  211.      
  212.      GetPort(&SavePort);
  213.     SetPort(WindThink);
  214.     FrameRect(&ThinkFRec[num]);
  215.     
  216.     h = ThinkRec[num].left+2;
  217.     v = ThinkRec[num].top+15;
  218.     TextMode(srcCopy);
  219.     for (i = 0; i <= maxThink; i++)
  220.     if (tm[i][0])
  221.     {
  222.         MoveTo(h, v);
  223.         DrawString(tm[i]);
  224.         v += 12;
  225.     } else break;
  226.  
  227.     SetPort(SavePort);
  228. }
  229.  
  230. pascal void UpdateValue(WindowPtr theWindow, int ItemNo)
  231. {
  232.      GrafPtr SavePort;
  233.      Str255 str;
  234.      
  235.      GetPort(&SavePort);
  236.     SetPort(WindThink);
  237.     FrameRect(&ValueFRec);
  238.     if (showvalue) {
  239.         TextMode(srcCopy);
  240.         NumToString(theScore, str);
  241.         FillRect(&ValueRec,(ConstPatternParam)&whitePat);
  242.         MoveTo(ValueRec.right-5-StringWidth(str),ValueRec.top+15);
  243.         DrawString(str);
  244.     } else FillRect(&ValueRec,(ConstPatternParam)&whitePat);
  245.     SetPort(WindThink);
  246. }
  247.  
  248. pascal void UpdateCase(WindowPtr theWindow, int ItemNo)
  249. {
  250.      GrafPtr SavePort;
  251.      
  252.     GetPort(&SavePort);
  253.     SetPort(WindBoard);
  254.     if (MouseX)
  255.     {
  256.         TextMode(srcCopy);
  257.         MoveTo(CaseRec.left+5,CaseRec.top+15);
  258.         FillRect(&CaseRec,(ConstPatternParam)&whitePat);
  259.         DrawChar(" abcdefgh"[MouseX]);
  260.         DrawChar(" 12345678"[MouseY]);
  261.     } else FillRect(&CaseRec,(ConstPatternParam)&whitePat);
  262.     SetPort(SavePort);
  263. }
  264.  
  265. pascal void UpdateListe(WindowPtr theWindow, int ItemNo)
  266. {
  267.     LUpdate(WindList->visRgn, List);
  268. }
  269.  
  270. void UpdateMenus()
  271. {
  272.     int i;
  273.     int moves, minutes;
  274.     int Item_No;
  275.     
  276.     if (GameCnt >= 0)
  277.         EnableItem(GetMHandle(EditMenu), 1);
  278.     else
  279.         DisableItem(GetMHandle(EditMenu), 1);
  280.     
  281.     if ((computer != player) && hint)
  282.         EnableItem(GetMHandle(OptionsMenu), 9);
  283.     else
  284.         DisableItem(GetMHandle(OptionsMenu), 9);
  285.     
  286.     if (computer == player)
  287.         EnableItem(GetMHandle(OptionsMenu), 10);
  288.     else
  289.         DisableItem(GetMHandle(OptionsMenu), 10);
  290.     
  291.     moves = TCmoves[white];
  292.     minutes = TCminutes[white];
  293.     if ((moves == 60) && (minutes == 5)) Item_No = 1;
  294.     else
  295.     if ((moves == 60) && (minutes == 15)) Item_No = 2;
  296.     else
  297.     if ((moves == 60) && (minutes == 30)) Item_No = 3;
  298.     else
  299.     if ((moves == 40) && (minutes == 30)) Item_No = 4;
  300.     else
  301.     if ((moves == 40) && (minutes == 60)) Item_No = 5;
  302.     else
  303.     if ((moves == 40) && (minutes == 120)) Item_No = 6;
  304.     else
  305.     if ((moves == 40) && (minutes == 240)) Item_No = 7;
  306.     else
  307.     if ((moves == 1) && (minutes == 15)) Item_No = 8;
  308.     else
  309.     if ((moves == 1) && (minutes == 60)) Item_No = 9;
  310.     else
  311.     if ((moves == 1) && (minutes == 600)) Item_No = 10;
  312.     else Item_No = 12;
  313.  
  314.     for (i=1; i<=12; i++)
  315.         CheckItem(GetMHandle(WhiteMenu), i, i==Item_No);
  316.  
  317.     moves = TCmoves[black];
  318.     minutes = TCminutes[black];
  319.     if ((moves == 60) && (minutes == 5)) Item_No = 1;
  320.     else
  321.     if ((moves == 60) && (minutes == 15)) Item_No = 2;
  322.     else
  323.     if ((moves == 60) && (minutes == 30)) Item_No = 3;
  324.     else
  325.     if ((moves == 40) && (minutes == 30)) Item_No = 4;
  326.     else
  327.     if ((moves == 40) && (minutes == 60)) Item_No = 5;
  328.     else
  329.     if ((moves == 40) && (minutes == 120)) Item_No = 6;
  330.     else
  331.     if ((moves == 40) && (minutes == 240)) Item_No = 7;
  332.     else
  333.     if ((moves == 1) && (minutes == 15)) Item_No = 8;
  334.     else
  335.     if ((moves == 1) && (minutes == 60)) Item_No = 9;
  336.     else
  337.     if ((moves == 1) && (minutes == 600)) Item_No = 10;
  338.     else Item_No = 12;
  339.     
  340.     for (i=1; i<=12; i++)
  341.         CheckItem(GetMHandle(BlackMenu), i, i==Item_No);
  342.  
  343.     CheckItem(GetMHandle(PlayerMenu), 1, !bothsides && (opponent == white)
  344.                                          && (computer == black) && !force);
  345.     CheckItem(GetMHandle(PlayerMenu), 2, !bothsides && (opponent == black)
  346.                                          && (computer == white) && !force);
  347.     CheckItem(GetMHandle(PlayerMenu), 3, bothsides && !force);
  348.     CheckItem(GetMHandle(PlayerMenu), 4, !bothsides && force);
  349.     
  350.     CheckItem(GetMHandle(OptionsMenu), 1, easy);
  351.     CheckItem(GetMHandle(OptionsMenu), 2, reverse);
  352.     CheckItem(GetMHandle(OptionsMenu), 3, anim);
  353.     CheckItem(GetMHandle(OptionsMenu), 4, dither!=0);
  354.     CheckItem(GetMHandle(OptionsMenu), 5, post);
  355.     CheckItem(GetMHandle(OptionsMenu), 6, showvalue);
  356.     CheckItem(GetMHandle(OptionsMenu), 7, hashflag);
  357.  
  358. }
  359.  
  360.